package com.fmyexample.mcsecurityboot.modular.service;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fmyexample.mcsecurityboot.modular.mapper.UserMapper;
import com.fmyexample.mcsecurityboot.modular.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.text.MessageFormat;

/**
 * <p>
 * User 服务实现类
 * </p>
 *
 * @author ms
 * @since 2020-03-31
 */
@Service
@Slf4j
public class UserService extends ServiceImpl<UserMapper, User> implements IService<User> {

    /**
     * 初始化用户
     *
     * @return 是否初始化成功
     */
    public boolean init() {
        String pass = SecureUtil.md5("aaaaaa123456");
        User user = new User().setUserPhone("18888888888")
                .setPassword(pass)
                .setUserSalt("aaaaaa")
                .setUsername("user sl");
        if (save(user)) {
            log.info("初始化用户成功");
            log.info(MessageFormat.format("用户登录名：{0}，用户密码：{1}", "18888888888", "123456"));
            return true;
        }
        log.info("初始化用户失败");
        return false;
    }
}
